package com.cljz.peipei.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.cljz.peipei.R;
import com.cljz.peipei.base.App;
import com.cljz.peipei.base.BaseActivity;
import com.cljz.peipei.widget.PickerView;
import com.jakewharton.rxbinding.view.RxView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.router.Router;
import rx.functions.Action1;

/**
 * Created by apple on 2017/4/18.
 */

public class SetAgeActivity extends BaseActivity implements PickerView.onSelectListener {


    @BindView(R.id.fl_back)
    FrameLayout flBack;
    @BindView(R.id.tv_your_name)
    TextView tvYourName;
    @BindView(R.id.tv_age)
    TextView tvAge;
    @BindView(R.id.btn_next)
    Button btnNext;
    @BindView(R.id.pv_select_age)
    PickerView pvSelectAge;
    List<String> ageList;
    private String sex;
    private Bundle bundle;

    @Override
    public void initData(Bundle savedInstanceState) {
        bundle = getIntent().getExtras();
        ageList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            ageList.add(String.valueOf(i + 1));
        }
        pvSelectAge.setData(ageList);
        pvSelectAge.setIsLoop(false);
        pvSelectAge.setCanScroll(true);
        pvSelectAge.setSelected(17);
    }

    @Override
    protected void initListener() {
        super.initListener();
        pvSelectAge.setOnSelectListener(this);
        RxView.clicks(btnNext)
                .compose(this.<Void>bindToLifecycle())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        bundle.putString("age", tvAge.getText().toString().trim());
                        Router.newIntent((Activity) App.getInstance())
                                .to(SetNicknameActivity.class)
                                .data(bundle)
                                .launch();
                    }
                });
        RxView.clicks(flBack)
                .compose(this.<Void>bindToLifecycle())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Router.pop(SetAgeActivity.this);
                    }
                });
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_set_age;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    public void onSelect(String text) {
        tvAge.setText(text);
    }
}
